package cn.thread;




import view.window.GameMusic;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeManagement {

    public static void main(String args[]) throws IOException {
        boolean append=true;
        Date currentDate=new Date();
        SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        File fe=new File(System.getProperty("user.dir")+"/config.data");
//         if(!fe.exists())
//            fe.createNewFile();
    try(BufferedReader br=new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));
        FileOutputStream fos=new FileOutputStream(System.getProperty("user.dir")+"/log.txt",append);
        BufferedOutputStream bos=new BufferedOutputStream(fos);
        OutputStreamWriter osw=new OutputStreamWriter(bos);
        BufferedWriter bw=new BufferedWriter(osw);
//        InputStream dis=new DataInputStream(new FileInputStream(System.getProperty("user.dir")+"/config.data"));
//        OutputStream dos=new DataOutputStream(new FileOutputStream(System.getProperty("user.dir")+"/config.data"))
        ){
//      if(fe.length()==0)
//      ((DataOutputStream) dos).writeLong(0);
       System.out.println("=====================时间管理提高效率========================");
       System.out.println("输入1开始计时\t输入2停止计时获取学习时间\t输入3获取当前时间");
        String msg="";
        char[] chars=new char[3];
        while (!msg.equals("exit")){
           msg=br.readLine();
           switch (msg){
               case "1":
                   System.out.println("学习项目：\t");
                   msg="学习项目：\t"+br.readLine();
                   bw.write(msg);
                   bw.newLine();
                   System.out.println("开始计时");
                 currentDate=new Date();
                String current= sf.format(currentDate);
                System.out.println(current);
                bw.write("学习开始时间：\t"+current);
                bw.newLine();
                bw.flush();
                   try {
                       Thread.sleep(1000*4);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   GameMusic.Play("C:\\Users\\86158\\Desktop\\Piiinnng _ 银临 - 不离.wav");


                   break;
               case "2":
                   msg="exit";
                   String newTime= sf.format(new Date(new Date().getTime()-currentDate.getTime()));
                   long time=(new Date().getTime()-currentDate.getTime())/1000;

                   int hh=(int)(time/(60*60));
                   int mm=(int)(time-hh*(60*60))/60;
                   int ss=(int)(time%60);

                   System.out.println("你的学习时间："+hh+"小时"+mm+"分钟"+ss+"秒");
//                   long sum=((DataInputStream) dis).readLong();
//                   sum=sum+time;
//                   System.out.println(sum);
//                   ((DataOutputStream) dos).writeLong(sum);
//                   dos.flush();
//                    sum=((DataInputStream) dis).readLong();
                   bw.write("你的学习时间："+hh+"小时"+mm+"分钟"+ss+"秒");
                   bw.newLine();
                   bw.flush();
//                   bw.write("你学习的总时长："+sum/3600+"小时"+(sum-(sum/3600)*3600)/60+"分钟"+sum%60+"秒");
                   bw.newLine();
                   bw.flush();
                   break;
               case "3":
                   boolean flag=true;

                   Date newDate=new Date();
                   while (flag) {
                       try {
                           Thread.sleep(1000);
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }

                       Date timeDate = new Date();
                       timeDate=new Date(timeDate.getTime()+1000);
                       String d = sf.format(timeDate);
                       System.out.println(d);
                       if(newDate.getTime()+1000*10<timeDate.getTime()){
                           flag=false;
                       }

                   }
                   break;

           }
//           bw.write(msg);
//            bw.newLine();
//            bw.flush();

        }

    }catch (IOException e){
        e.printStackTrace();
    }

    }

    public static void time() {


    }
}
class TimeTest implements Runnable{
    public static void main(String args[]) throws IOException {
        OutputStream dos=new DataOutputStream(new FileOutputStream("config.data"));
        InputStream dis=new DataInputStream(new FileInputStream("config.data"));
        //((DataOutputStream) dos).writeLong(1111);
        long a = ((DataInputStream) dis).readLong();
        System.out.println(a);
    }

    @Override
    public void run() {

    }
}
